<template>
    <div class="home-product"> 
        <MyPanel v-for="item in products" :key="item.id" :title="item.name">
            <!-- 使用右侧插槽 -->
             <template #right>
                <div class="sub">
                    <router-link v-for="sub in item.children" :key="sub.id" to="/">{{ sub.name }}</router-link>
                </div>
                <AppMore></AppMore>
             </template>
             <div class="goods">
                <!-- 左侧 -->
                 <router-link class="left" to="/">
                    <img :src="item.picture">
                 </router-link>
                 <!-- 右侧部分 -->
                  <div class="right">
                        <ul class="good-list">
                            <li v-for="good in item.goods" :key="good.id">
                                <MyGoodsItem :good="good"></MyGoodsItem>
                            </li>
                        </ul>
                  </div>
             </div>
        </MyPanel>
    </div>
</template>

<script>
import MyPanel from '@/components/MyPanel.vue';
import MyGoodsItem from '@/components/MyGoodsItem.vue';
import { getProduct } from '@/api';
import { ref } from 'vue';
   export default {
    components: {
        MyPanel,
        MyGoodsItem,
    },
    // eslint-disable-next-line no-unused-vars
    setup(props) {
        const products = ref([]);
        const getProducts = async() => {
            try {
                const res = await getProduct();
                console.log(res)
                if(res.msg === '操作成功'){
                    products.value = res.result;
                }
            } catch (error) {
                console.log(error)
            }
        }
        getProducts();
        return { products }
    }
   }
</script>
<style scoped lang='less'>
.home-product {
    background-color: #fff;
    .sub {
        a {
            font-size: 16px;
            padding: 2px 10px;
            border-radius: 4px;
            margin: 0 7px;
            &:hover {
                background-color: @xtxColor;
            }
            &:last-child {
                margin-right: 40px;
            }
        }
    }

    .goods {
        height: 610px;
        display: flex;
        .left {
            width: 300px;
            margin-right: 10px;
            img {
                width: 100%;
                height: 100%;
            }
        }
        .right {
            .good-list {
                display: flex;
                flex-wrap: wrap;
                justify-content: space-between;
            }
        }
    }
}
</style>